home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
editdemo
/
vbinput.bas
< prev
Wrap
BASIC Source File
|
1995-05-09
|
22KB
|
727 lines
'(c) 1991 by Keith Milligan
' 100 Lee Road 605
' Smiths, AL 36877
' 205-291-9712 Home
' 205-298-1974 Work
' Compuserve ID = 70645,520
'Use these routines if they will help you. You can use,
'modify, copy, or distribute with a clear concience.
'Visual Basic 1.0 input routines
'These routine are use two events for each text control.
'There is a Sub for the KeyPress event and a corresponding
'Function for the LostFocus Event. The KeyPress (KP) routine
'restricts certain keystrokes and the LostFocus (LF) routine
'validates the data entered in the text control and assigns
'the entered data to a variable.
'Date
' Sub DateKP(ThisControl, KeyAscii)
' Function DateLF$(ThisControl, EarliestDate$)
' Format of EarliestDate$ is "yymmdd".
' Accepts date enter in one of the following formats:
' 60491, 060491, 06/04/91, or 6/4/91
' Returns date in the format 910604.
'MultPrice
' Sub MultPriceKP(ThisControl, KeyAscii)
' Function MultPriceLF$(ThisControl)
' Used to accept retail prices. For example 3 for $1.00.
' Accepts and returns in the following formats:
' Input Returns
' 149 01/01.49
' 1.49 01/01.49
' 3/49 03/00.49
' 3/.49 03/00.49
'Point2
' Sub Point2KP(ThisControl, Length%, KeyAscii)
' Function Point2LF(ThisControl, Min#, Max#)
' Accepts number with two digits to the right of the decimal point.
' Maximum length = Length%
' Minimum value = Min#
' Maximum value = Max#
' Example 123.49
'Point4
' Sub Point4KP(ThisControl, Length%, KeyAscii)
' Function Point4LF(ThisControl, Min#, Max#)
' Accepts number with four digits to the right of the decimal point.
' Maximum length = Length%
' Minimum value = Min#
' Maximum value = Max#
' Example 123.4978
'Str
' Sub StrKP(ThisControl, Length%, KeyAscii)
' No LF function for this routine just move text to string in
' LostFocus Event.
' Accepts string of length less than or equal to Length%.
'UCStr
' Sub UCStrKP(ThisControl, Length%, KeyAscii)
' No LF function for this routine just move text to string in
' LostFocus Event.
' Accepts string of length less than or equal to Length%.
' Converts characters to upper case as typed.
'Long
' Sub LongKP(ThisControl, Length%, KeyAscii)
' Function LongLF&(ThisControl, Min&, Max&)
' Accepts long integer amount.
'Int
' Sub IntKP(ThisControl, Length%, KeyAscii)
' Function IntLF%(ThisControl, Min%, Max%)
' Same as Long but accepts normal integer amounts
'Curr2
' Sub Curr2KP(ThisControl, Length%, KeyAscii)
' Function Curr2LF@(ThisControl, Min@, Max@)
' Same as Point2 but for currency data type.
'Curr4
' Sub Curr4KP(ThisControl, Length%, KeyAscii)
' Function Curr4LF(ThisControl, Min@, Max@)
' Same as Point4 but for currency data type.
'DateSer
' Sub DateSerKP(Thiscontrol, KeyAscii)
' Function DateSerLF@(ThisControl, EarliestDate$)
' Same as Date but returns date serial number instead of yymmdd.
'
Sub Curr2KP (ThisControl As Control, Length%, KeyAscii As Integer)
If Len(ThisControl.Text) = Length% Then
If KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
Else
C$ = Chr$(KeyAscii)
StringLength% = Len(ThisControl.Text)
DecimalPosition% = InStr(ThisControl.Text, ".")
If StringLength% - DecimalPosition% = 2 And DecimalPosition% <> 0 Then
If ThisControl.SelStart < DecimalPosition% Then
Select Case C$
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr$(8)
Case "-"
If ThisControl.SelStart <> 0 Or InStr(ThisControl.Text, "-") <> 0 Then
KeyAscii = 0
Beep
End If
Case Else
KeyAscii = 0
Beep
End Select
ElseIf KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
Else
Select Case C$
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr$(8)
Case "."
If InStr(ThisControl.Text, ".") <> 0 Then
KeyAscii = 0
Beep
End If
Case "-"
If ThisControl.SelStart <> 0 Or InStr(ThisControl.Text, "-") <> 0 Then
KeyAscii = 0
Beep
End If
Case Else
KeyAscii = 0
Beep
End Select
End If
End If
End Sub
Function Curr2LF@ (ThisControl As Control, Min@, Max@)
Test@ = Val(ThisControl.Text)
If ThisControl.Text <> "" Then
If Test@ < Min@ Or Test@ > Max@ Then
Beep
Msg$ = "Number must be between " + Str$(Min@) + " and " + Str$(Max@)
MsgBox Msg$, 0, "Warning"
ThisControl.SetFocus
Else
Curr2LF@ = Test@
End If
End If
End Function
Sub Curr4KP (ThisControl As Control, Length%, KeyAscii As Integer)
If Len(ThisControl.Text) = Length% Then
If KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
Else
C$ = Chr$(KeyAscii)
StringLength% = Len(ThisControl.Text)
DecimalPosition% = InStr(ThisControl.Text, ".")
If StringLength% - DecimalPosition% = 4 And DecimalPosition% <> 0 Then
If ThisControl.SelStart < DecimalPosition% Then
Select Case C$
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr$(8)
Case "-"
If ThisControl.SelStart <> 0 Or InStr(ThisControl.Text, "-") <> 0 Then
KeyAscii = 0
Beep
End If
Case Else
KeyAscii = 0
Beep
End Select
ElseIf KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
Else
Select Case C$
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr$(8)
Case "."
If InStr(ThisControl.Text, ".") <> 0 Then
KeyAscii = 0
Beep
End If
Case "-"
If ThisControl.SelStart <> 0 Or InStr(ThisControl.Text, "-") <> 0 Then
KeyAscii = 0
Beep
End If
Case Else
KeyAscii = 0
Beep
End Select
End If
End If
End Sub
Function Curr4LF (ThisControl As Control, Min@, Max@)
Test@ = Val(ThisControl.Text)
If ThisControl.Text <> "" Then
If Test@ < Min@ Or Test@ > Max@ Then
Beep
Msg$ = "Number must be between " + Str$(Min@) + " and " + Str$(Max@)
MsgBox Msg$, 0, "Warning"
ThisControl.SetFocus
Else
Curr4LF! = Test@
End If
End If
End Function
Sub DateKP (ThisControl As Control, KeyAscii As Integer)
C$ = Chr$(KeyAscii)
Test$ = ThisControl.Text
If Len(Test$) = 6 And InStr(Test$, "/") = 0 Then
If KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
ElseIf Len(Test$) = 8 And InStr(Test$, "/") <> 0 Then
If KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
Else
Select Case C$
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr$(8), "/"
Case Else
KeyAscii = 0
Beep
End Select
End If
End Sub
Function DateLF$ (ThisControl As Control, EarliestDate$)
If ThisControl.Text <> "" Then
BadDate$ = "N"
InDate$ = ThisControl.Text
If Len(InDate$) = 5 Then
InDate$ = "0" + InDate$
ElseIf Len(InDate$) = 6 Then
If InStr(InDate$, "/") <> 0 Then
InDate$ = "0" + Left$(InDate$, 1) + "0" + Mid$(InDate$, 3, 1) + Mid$(InDate$, 5, 2)
End If
ElseIf Len(InDate$) = 7 Then
If Mid$(InDate$, 2, 1) = "/" Then
InDate$ = "0" + Left$(InDate$, 1) + Mid$(InDate$, 3, 2) + Mid$(InDate$, 6, 2)
Else
InDate$ = Left$(InDate$, 2) + "0" + Mid$(InDate$, 4, 1) + Mid$(InDate$, 6, 2)
End If
ElseIf Len(InDate$) = 8 Then
InDate$ = Left$(InDate$, 2) + Mid$(InDate$, 4, 2) + Mid$(InDate